#include "file_ctrl.h"
#include "storage_api.h"
#include "crossplat_def.h"
#include "cross_com.h"

CFileInfo_manager::CFileInfo_manager()
{
	m_lstBufSz = 0;
	m_fileNum  = 0;
	m_pRetNum = NULL;
	m_fileLstbuf = NULL;
}

CFileInfo_manager::~CFileInfo_manager()
{

}

int CFileInfo_manager::Init(int maxFileNum)
{
	int ret    = 0;

	m_lstBufSz   = 4 + sizeof(RECORD_SEGMENT) * maxFileNum;
	m_fileLstbuf = new char[m_lstBufSz];
	if(m_fileLstbuf == NULL)
	{
		fprintf(stderr,"File List new buf fail. \n");
		return ERR_DATA_BUF_EMPYT;
	}
	m_pRetNum = (int*)m_fileLstbuf;
	m_maxNum  = maxFileNum;
	printf(" CFileInfo_manager::Init maxFileNum %d  m_lstBufSz %d .\n",
		maxFileNum,
		m_lstBufSz
	);

	return ret;
}

int CFileInfo_manager::GetFileLst(FILE_LST_REQ * fileReq)
{
	int ret = 0;
	char * pLstBuf = m_fileLstbuf + 4;
	int clientID = 0;
	if (m_lstBufSz == 0)
	{
		return 0;
	}

	if (m_fileLstbuf == NULL)
	{
		printf("buffer is NULL.\n", m_fileLstbuf);
		m_fileLstbuf = new char[m_lstBufSz];
	}

	printf("telnet SearchRec chbit %d recType %d m_lstBufSz %d  .\n",fileReq->chBit,fileReq->recType, m_lstBufSz);
	//PrintTime(fileReq->tmStart, fileReq->tmEnd,"GetFileLst time");
	if (fileReq->merge)
	{
		m_fileNum = ret = STFS_SearchHistoryRec((unsigned char *)pLstBuf, m_lstBufSz, fileReq->tmStart, fileReq->tmEnd,
			0,/*fileReq->chBit*/ fileReq->recType, clientID);
	}
	else
	{
		m_fileNum = ret = STFS_SearchRec(pLstBuf, m_lstBufSz, fileReq->tmStart, fileReq->tmEnd,
			fileReq->chBit, fileReq->recType, fileReq->storType, clientID);
	}


	if( NULL != m_pRetNum)
	{
		*m_pRetNum = ret;
		printf("CFileInfo_manager::GetFileLst retNum %d .\n", ret);
	}

	return ret;
}

#if 0
int CFileInfo_manager::DelFile(FILE_DEL_INFO_REQ * pDelInfo)
{
	int ret = 0;


	return ret;
}
#endif

int CFileInfo_manager::GetSDCardStatus()
{
	int ret = 0;

	return ret;
}


